#include<bits/stdc++.h>
using namespace std;
#define double long double
int t;
int n,m,l,v;
struct car{
    int d,v,a;
}c[100010];
int ds[100010];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(;t>=1;t--){
        bitset<20>b[25];
        int y=0;
        int cnt=0;
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;i++){
            cin>>c[i].d>>c[i].v>>c[i].a;
            y+=c[i].a;
        }
        for(int i=1;i<=m;i++){
            cin>>ds[i];
        }
        sort(ds+1,ds+m+1);
        for(int i=1;i<=n;i++){
            if(c[i].a!=0){
                if(c[i].a>0){
                    double s;
                    if(c[i].v<=v){
                        s=round(((double)v*v-(double)c[i].v*c[i].v)/(2*c[i].a));
                    }
                    else s=-0.5;
                    int k=upper_bound(ds+1,ds+1+m,s+c[i].d)-ds;
                    if(k!=m+1){cnt++;/*cout<<i<<" "<<s<<" "<<k<<endl;*/}
                }
                if(c[i].a<0){
                    if(c[i].v<=v)continue;
                    else{
                        double s=round(((double)v*v-(double)c[i].v*c[i].v)/(2*c[i].a));
                        int k=lower_bound(ds+1,ds+1+m,c[i].d)-ds;
                        if(ds[k]<s+c[i].d){cnt++;}
                    }
                }
            }
            if(c[i].a==0){
                if(c[i].v<=v)continue;
                else{
                    int k=lower_bound(ds+1,ds+m+1,c[i].d)-ds;
                    if(k!=m+1){cnt++;}
                }
            }
        }
        cout<<cnt<<" ";
        if(cnt==0)cout<<m<<endl;
        else cout<<m-1<<endl;
        //bitset<20>b[20];
    }
    return 0;
}

